/*
 时间格式化显示过滤器
 By: JasonChao
 */
(function(root, factory) {
	if(typeof define === 'function' && define.amd) {
		// AMD. Register as an anonymous module.
		define(['exports', 'vue'], factory);
	} else if(typeof exports === 'object' && typeof exports.nodeName !== 'string') {
		// CommonJS
		factory(exports, require('vue'));
	} else {
		// Browser globals
		factory(({}), root.Vue);
	}
}(this, function(exports, Vue) {
	Vue.dateFilter = {
		install: function(Vue, options) {
			var definition = function(value, type){
				var dateStr = value;
				switch(type) {
					case "timestamp": //需要到毫秒级
						var today = new Date(),
							valueDay = new Date(parseInt(value)),
							todayDate = today.getFullYear().toString().slice(2) + "/" + (today.getMonth()+1) + "/" + today.getDate(),
							valueDate = valueDay.getFullYear().toString().slice(2) + "/" + (valueDay.getMonth()+1) + "/" + valueDay.getDate(),
							valueTime = valueDay.getHours() + ":" + valueDay.getMinutes();
							if(todayDate == valueDate){
								dateStr = valueTime;
							}else {
								dateStr = valueDate;
							}
						break;
					default: 
						dateStr = value.match(/\d{2}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}/ig);
						if(dateStr){
							dateStr = dateStr[0].replace(/-/g,"/");	
						}
						
				}
				return dateStr;
			}
			Vue.filter('dateFilter', definition);
		}
	}
}));